import os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
base_dir=os.path.abspath(os.path.dirname(__file__))
app=Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI']='sqlite:///'+os.path.join(base_dir,'data1.sqlite')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS']=True
app.config['SQLALCHEMY_COMMIT_TEARDOWN']=True
db=SQLAlchemy(app)
class User(db.Model):
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(100), nullable=False)
    password = db.Column(db.String(100), nullable=False)
    status = db.Column(db.Integer, nullable=False)
    createdate=db.Column(db.DateTime,nullable=False,default=datetime.now)
@app.route("/initdb")
def initdb():
    # 创建数据库表的基本指令：
    # 清除数据库里的所有数据, 谨慎使用
    db.drop_all()
    # 创建所有的表
    db.create_all()
    return "初始化数据库成功..."
if __name__=="__main__":
    app.run()
